home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-25 | 1.9 KB | 69 lines | [TEXT/CCL2] |
-
- (in-package "VOICE-TOOLKIT")
-
- (defun make-twin (word count prob)
- (list word count prob))
-
- (defun twin-count (twin)
- (second twin))
-
- (defun twin-word (twin)
- (first twin))
-
- (defun twin-prob (twin)
- (third twin))
-
- (defun twin-weight (twin)
- (/ (twin-prob twin) (twin-count twin)))
-
- (defparameter *twintable* (make-hash-table :test #'equal))
-
- (defun hash-twin (word twin)
- (setf (gethash word *twintable*)
- (add-twin twin (gethash word *twintable*))))
-
- (defun add-twin (twin twinlist)
- (cond ((null twinlist) (list twin))
- ((equal (twin-word twin)
- (twin-word (first twinlist)))
- (cons (make-twin (twin-word twin)
- (+ (twin-count twin)
- (twin-count (first twinlist)))
- (+ (twin-prob twin)
- (twin-prob (first twinlist))))
- (rest twinlist)))
- (t (cons (first twinlist) (add-twin twin (rest twinlist))))))
-
- (defun report-twins ()
- (let ((report nil))
- (maphash #'(lambda (word twinlist)
- (setf report (cons (cons word twinlist) report)))
- *twintable*)
- report))
-
- (defun get-twins (word)
- (gethash word *twintable*))
-
- (defun file-twins (report)
- (let ((file
- (open "COOKIE:Voice Toolkit;Experience File"
- :direction :output
- :if-exists :overwrite
- :if-does-not-exist :create)))
- (write report :stream file)
- (close file)))
-
- (defun load-twins ()
- (let ((file
- (open "COOKIE:Voice Toolkit;Experience File"
- :direction :input
- :if-does-not-exist nil)))
- (mapcar #'(lambda (twinline)
- (mapcar #'(lambda (twin)
- (hash-twin (first twinline) twin))
- (rest twinline)))
- (if file (read file)))
- (close file)))
-
-
-